﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AsyncAwaitDemo01
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Test();
            //TaskTest();
            //Console.WriteLine("11111111111111111111111111111111" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss fff"));
            Console.ReadKey();
        }

        static async void NoReturnNoAwait()
        {
            Task task = Task.Run(() =>
            {
                Thread.Sleep(1000);
                Console.WriteLine($"NoReturnNoAwait sleep 3000");
            });
        }


        static async Task TaskTest()
        {
            using (var client = new WebClient())
            {
                try
                {

                    string content = await client.DownloadStringTaskAsync("http://www.baidu.com");
                    Console.WriteLine(content.Substring(0, 5) + DateTime.Now.ToString("yyyyMMdd HH:mm:ss fff"));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }

        static void Test()
        {
            for (int i = 0; i < 10; i++)
            {
                Task.Run(() =>
                {
                    while (true)
                    {
                        TaskTest1();
                        Console.WriteLine("111111111111111111111");
                    }
                });
            }
        }

        static async Task TaskTest1()
        {
            
                try
                {
                    Thread.Sleep(2000);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
        }
    }
}
